<?php include './application/views/common/zhs_header.php';?>

<?php include './application/views/common/zhs_usercenter_acnt.php';?>
<div class="inv_box w">
<?php include './application/views/common/zhs_usercenter_left.php';?>
  <div class="membd_right">
     <h3 class="membdrg_tit">交易密码找回</h3>
    <div class="mem_perbox">
 <form id="my_form">
<input type="hidden" name="act" value="set">
<input type="hidden" name="check" value="<?php echo $check;?>">
		<div class="user_right_border">
			<div class="l">设置交易密码：</div>
			<div class="c">
				<input type="password" maxlength="20" name="paypwd1" id="paypwd1">
			</div>
		</div>
		
		<div class="user_right_border">
			<div class="l">重复交易密码：</div>
			<div class="c">
				<input type="password" maxlength="20" name="paypwd2" id="paypwd2">
			</div>
		</div>
		<div class="user_right_border">
			<div class="l">手机验证码：</div>
			<div class="c">
				<div style="float: left;"><input type="text" id="ver_code" name="ver_code" style="width:45px;" maxlength="6"></div>
				<span id="phone_code" style="float: left;">
					<a href="javascript:;" class="regbtn0" onclick="phoneSubmit();" style="margin-top:2px; padding:0 8px; text-decoration: underline"> 获取手机验证码</a>
				</span>
			</div>
		</div>
		<div class="user_right_border">
			<div class="l"></div>
			<div class="c">
			<input type="button" style="cursor:pointer; margin:12px 0 0 110px;;" class="little_button" size="30" value="确认提交" onclick="toSubmit();">
			</div>
		</div>
</form>
<script>
<?php if($msg!=''){?>
$(function(){
	$('#dialog').dialog({
		modal:true,
		title:'系统提示',
		buttons:{"确定":function(){$(this).dialog("close");}},
		close: function() {
			location="<?php echo $url;?>";
		}
	}); 
	$("#msg").html("<?php echo $msg;?>");
});
<?php }?>

function toSubmit(){
	var options = {
		url : GetUrlRelativePath(),
		clearForm :true,
		resetForm :true,
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}},
					close: function() {
						location=ret.url;
					}
				}); 
				$("#msg").html("操作成功");
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#my_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var pregName = /(?!^(\d+|[a-zA-Z]+|[~!#$^&?_]+)$)^[\w~!#$\^&?_]+$/;
	var err = '';
	if($('#paypwd1').val()==''){
		err = '请输入交易密码';
	}else if($('#paypwd2').val()==''){
		err = '请重复交易密码';
	}else if(!pregName.test($('#paypwd1').val()) || $('#paypwd1').val().length <=5){
		err = '无效新密码，必须含有数字+字母，其中只允许~!#$^&?_字符';
	}else if($('#paypwd1').val()!=$('#paypwd2').val()){
		err = '两次密码输入不一致';
	}else if($('#ver_code').val()==''){
		err = '请输入验证码';
	}
	
	if(err==''){
		return true;
	}else{
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}},
			close: function() {
				$("#my_form").resetForm();
			}
		}); 
		$("#msg").html(err);
		return false;
	}
}
function phoneSubmit(){
	$("#phone_code").html('处理中，请等待');
	$.ajax({
		type: "post",
		url: "/reg/sendsms.html",
		success: function(ret){
			if(ret.info == 1){
				phone_countdown();
			}else{
				$("#phone_code").html(ret.msg);
				setTimeout(function(){
				$("#phone_code").html('<a href="javascript:;" onclick="phoneSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
					
				},3000);
			}
		},
		dataType: "json"
	});	
}
function phone_countdown(){
	var count = 180;
	var countdown = setInterval(CountDown, 1000); 
	function CountDown() {
		$("#phone_code").html('手机验证码已发送,请等待 <font style="color:#a71e32;">'+count+"</font>秒");
		if (count == 0) {
			$("#phone_code").html('<a href="javascript:;" onclick="phoneSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
			clearInterval(countdown);
		}
		count--;
	}
}
</script>
   </div>
</div> 
</div>

<?php include './application/views/common/zhs_footer.php';?>
<?php include './application/views/common/zhs_right.php';?>
    